﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using DevExpress.Web.Mvc;
using DevExpress.Web.ASPxGridView;
using System.Data;
using EnterpriseFund.Common;
using DevExpress.XtraReports.UI;
using DevExpress.XtraPrinting;
using System.Text;

namespace EnterpriseFund.Controllers
{
    public class QueryAddCreditsController : Controller
    {
        //
        // GET: /QueryAddCredits/

        public ActionResult Index()
        {
            BLL.SB_ZSXX SB_ZSXXBLL = new BLL.SB_ZSXX();
            string year = OperateSession.get(GlobalConstant.PARAM_SYSYEAR);
            ViewData["AddCredits"] = 5000000;
            ViewData["year"] = year;
            return View();
        }

        public DataTable GetDate(DataSet ds, string year,List<Model.TaxClassAllowance> list)
        {
            DataTable newDt = new DataTable();
            newDt.Columns.Add("xh");
            newDt.Columns.Add("NSRBM");
            newDt.Columns.Add("NSRMC");
            int i = 1;
            foreach (Model.TaxClassAllowance l in list)
            {
                newDt.Columns.Add("se" + i, typeof(decimal));
                i++;
            }
            newDt.Columns.Add("sumse", typeof(decimal));
            i = 1;
            foreach (Model.TaxClassAllowance l in list)
            {
                newDt.Columns.Add("yse" + i, typeof(decimal));
                i++;
            }
            newDt.Columns.Add("ysumse", typeof(decimal));
            newDt.Columns.Add("AddCredits", typeof(decimal), "sumse-ysumse");

            int z = 1;
            foreach (DataRow dr in ds.Tables[0].Rows)
            {
                DataRow ndr = newDt.NewRow();
                foreach (DataColumn dc in newDt.Columns)
                {
                    if (dc.ColumnName != "xh" && dc.ColumnName != "AddCredits")
                    {
                        ndr[dc.ColumnName] = dr[dc.ColumnName];
                    }
                    else
                    {
                        ndr[dc.ColumnName] = z;
                    }
                }
                z++;
                newDt.Rows.Add(ndr);
            }
            DataRow hjdr = newDt.NewRow();
            foreach (DataColumn dc in newDt.Columns)
            {
                if (dc.DataType == typeof(decimal))
                {
                    hjdr[dc.ColumnName] = newDt.Compute("sum([" + dc.ColumnName + "])", "");
                }
                if (dc.ColumnName == "xh")
                {
                    hjdr["xh"] = "合计";
                }
            }
            newDt.Rows.Add(hjdr);

            return newDt;
        }



        public ActionResult QueryAddCreditsList(string FYear, string AddCredits)
        {
            DataTable dt = AlltoData(FYear, AddCredits);
            ViewData["showData"] = dt;

            return View();
        }
     
       
        private DataTable AlltoData(string FYear, string AddCredits)
        {
            string filter = "1=1";
           
            if (AddCredits == "")
            {
                AddCredits = "0";
            }
            BLL.SB_ZSXX SB_ZSXXBLL = new BLL.SB_ZSXX();

            BLL.TaxClassAllowance taxClassAllowanceBLL = new BLL.TaxClassAllowance();
            List<Model.TaxClassAllowance> list = taxClassAllowanceBLL.GetModelList("FYear='" + FYear + "'");
            ViewData["taxClassAllowanceList"] = list;
            string strwhere3 = "";
            int i = 1;
            string sumstr1 = "";
            foreach (Model.TaxClassAllowance tc in list)
            {
                if (strwhere3 == "")
                {
                    if (tc.FSQLCondition != "")
                    {
                        strwhere3 += @"SUM(CASE WHEN ZSXM_DM = '" + tc.FTaxClassNo + "' AND " + tc.FSQLCondition + " THEN SE END) AS se" + i;
                    }
                    else
                    {
                        strwhere3 += @"SUM(CASE WHEN ZSXM_DM = '" + tc.FTaxClassNo + "' THEN SE END) AS se" + i;
                    }
                }
                else
                {
                    if (tc.FSQLCondition != "")
                    {
                        strwhere3 += @",SUM(CASE WHEN ZSXM_DM = '" + tc.FTaxClassNo + "' AND " + tc.FSQLCondition + " THEN SE END) AS se" + i;
                    }
                    else
                    {
                        strwhere3 += @",SUM(CASE WHEN ZSXM_DM = '" + tc.FTaxClassNo + "' THEN SE END) AS se" + i;
                    }
                }
                if (sumstr1 == "")
                {
                    sumstr1 += "ISNULL(se" + i + ",0)";
                }
                else
                {
                    sumstr1 += "+ISNULL(se" + i + ",0)";
                }
                i++;
            }


            string strwhere4 = "";
            i = 1;
            string sumstr2 = "";
            foreach (Model.TaxClassAllowance tc in list)
            {
                if (strwhere4 == "")
                {
                    if (tc.FSQLCondition != "")
                    {
                        strwhere4 += @"SUM(CASE WHEN ZSXM_DM = '" + tc.FTaxClassNo + "' AND " + tc.FSQLCondition + " THEN SE END) AS yse" + i;
                    }
                    else
                    {
                        strwhere4 += @"SUM(CASE WHEN ZSXM_DM = '" + tc.FTaxClassNo + "' THEN SE END) AS yse" + i;
                    }
                }
                else
                {
                    if (tc.FSQLCondition != "")
                    {
                        strwhere4 += @",SUM(CASE WHEN ZSXM_DM = '" + tc.FTaxClassNo + "' AND " + tc.FSQLCondition + " THEN SE END) AS yse" + i;
                    }
                    else
                    {
                        strwhere4 += @",SUM(CASE WHEN ZSXM_DM = '" + tc.FTaxClassNo + "' THEN SE END) AS yse" + i;
                    }
                }
                if (sumstr2 == "")
                {
                    sumstr2 += "ISNULL(yse" + i + ",0)";
                }
                else
                {
                    sumstr2 += "+ISNULL(yse" + i + ",0)";
                }
                i++;
            }

            ViewData["year"] = FYear;
            BLL.Common CommonBLL = new BLL.Common();
            string str = CommonBLL.GetGetRejectTaxSqlByYear(FYear);
            string strwhere1 = "";
            if (str != "" && str != "( NULL)     ")
            {
                strwhere1 = @"   NOT EXISTS (SELECT  ZSXH
         FROM fund.V_SB_ZSXX s WHERE (" + str + @")  AND
                                   r.FDataSource = s.FDataSource AND
                                   r.ZSXH = s.ZSXH ) and DATEDIFF(DAY,RKRQ,'" + FYear + "-01-01')<=0 AND DATEDIFF(DAY,RKRQ,'" + FYear + "-12-31')>=0 ";
            }
            else
            {
                strwhere1 = @" DATEDIFF(DAY,RKRQ,'" + FYear + "-01-01')<=0 AND DATEDIFF(DAY,RKRQ,'" + FYear + "-12-31')>=0 ";
            }

            string year2 = (int.Parse(FYear) - 1).ToString();
            ViewData["Syear"] = year2;
            string str2 = CommonBLL.GetGetRejectTaxSqlByYear(year2);
            string strwhere2 = "";
            if (str != "" && str != "( NULL)     ")
            {
                strwhere2 = @"   NOT EXISTS (SELECT  ZSXH
         FROM fund.V_SB_ZSXX s WHERE (" + str + @")  AND
                                   r.FDataSource = s.FDataSource AND
                                   r.ZSXH = s.ZSXH ) and DATEDIFF(DAY,RKRQ,'" + year2 + "-01-01')<=0 AND DATEDIFF(DAY,RKRQ,'" + year2 + "-12-31')>=0 ";
            }
            else
            {
                strwhere2 = @" DATEDIFF(DAY,RKRQ,'" + year2 + "-01-01')<=0 AND DATEDIFF(DAY,RKRQ,'" + year2 + "-12-31')>=0 ";
            }

            StringBuilder strSql = new StringBuilder();

            strSql.Append(@"SELECT  y.NSRBM,y.NSRMC, z.*,w.*  FROM (
SELECT *,(" + sumstr1 + @") AS sumse FROM (
SELECT NSRDZDAH," + strwhere3 + @"
 FROM fund.V_SB_ZSXX r  
 where    " + strwhere1 + @"
          GROUP BY NSRDZDAH,YEAR(RKRQ)
          ) AS a WHERE " + sumstr1 + @" >0
         ) AS z
         LEFT JOIN (
         SELECT *,(" + sumstr2 + @") AS ysumse FROM (
SELECT NSRDZDAH as YNSRDZDAH," + strwhere4 + @"
 FROM fund.V_SB_ZSXX r  
 where   " + strwhere2 + @"
          GROUP BY NSRDZDAH,YEAR(RKRQ)
          ) AS a WHERE " + sumstr2 + @" >0
          ) w ON z.NSRDZDAH = w.YNSRDZDAH   LEFT JOIN fund.V_DJ_NSRXX y ON z.NSRDZDAH=y.NSRDZDAH  WHERE z.sumse-w.ysumse>" + AddCredits);
            if (filter.Trim() != "")
            {
                strSql.Append(" and  " + filter);
            }

            DataSet ds = SB_ZSXXBLL.GetAddCredits(strSql.ToString());
            ViewData["AddCredits"] = AddCredits;
            ViewData["year"] = FYear;
            DataTable dt = GetDate(ds, FYear, list);
            return dt;
        }

        public ActionResult ExportToXls()
        {
            string FYear;
            string AddCredits;
            string filter = "1=1";
            AddCredits = Fetch.Post("hAddCredits");
            FYear = Fetch.Post("hFYear");
            BLL.SB_ZSXX SB_ZSXXBLL = new BLL.SB_ZSXX();

            BLL.TaxClassAllowance taxClassAllowanceBLL = new BLL.TaxClassAllowance();
            List<Model.TaxClassAllowance> list = taxClassAllowanceBLL.GetModelList("FYear='" + FYear + "'");

            string strwhere3 = "";
            int i = 1;
            string sumstr1 = "";
            foreach (Model.TaxClassAllowance tc in list)
            {
                if (strwhere3 == "")
                {
                    if (tc.FSQLCondition != "")
                    {
                        strwhere3 += @"SUM(CASE WHEN ZSXM_DM = '" + tc.FTaxClassNo + "' AND " + tc.FSQLCondition + " THEN SE END) AS se" + i;
                    }
                    else
                    {
                        strwhere3 += @"SUM(CASE WHEN ZSXM_DM = '" + tc.FTaxClassNo + "' THEN SE END) AS se" + i;
                    }
                }
                else
                {
                    if (tc.FSQLCondition != "")
                    {
                        strwhere3 += @",SUM(CASE WHEN ZSXM_DM = '" + tc.FTaxClassNo + "' AND " + tc.FSQLCondition + " THEN SE END) AS se" + i;
                    }
                    else
                    {
                        strwhere3 += @",SUM(CASE WHEN ZSXM_DM = '" + tc.FTaxClassNo + "' THEN SE END) AS se" + i;
                    }
                }
                if (sumstr1 == "")
                {
                    sumstr1 += "ISNULL(se" + i + ",0)";
                }
                else
                {
                    sumstr1 += "+ISNULL(se" + i + ",0)";
                }
                i++;
            }


            string strwhere4 = "";
            i = 1;
            string sumstr2 = "";
            foreach (Model.TaxClassAllowance tc in list)
            {
                if (strwhere4 == "")
                {
                    if (tc.FSQLCondition != "")
                    {
                        strwhere4 += @"SUM(CASE WHEN ZSXM_DM = '" + tc.FTaxClassNo + "' AND " + tc.FSQLCondition + " THEN SE END) AS yse" + i;
                    }
                    else
                    {
                        strwhere4 += @"SUM(CASE WHEN ZSXM_DM = '" + tc.FTaxClassNo + "' THEN SE END) AS yse" + i;
                    }
                }
                else
                {
                    if (tc.FSQLCondition != "")
                    {
                        strwhere4 += @",SUM(CASE WHEN ZSXM_DM = '" + tc.FTaxClassNo + "' AND " + tc.FSQLCondition + " THEN SE END) AS yse" + i;
                    }
                    else
                    {
                        strwhere4 += @",SUM(CASE WHEN ZSXM_DM = '" + tc.FTaxClassNo + "' THEN SE END) AS yse" + i;
                    }
                }
                if (sumstr2 == "")
                {
                    sumstr2 += "ISNULL(yse" + i + ",0)";
                }
                else
                {
                    sumstr2 += "+ISNULL(yse" + i + ",0)";
                }
                i++;
            }

            BLL.Common CommonBLL = new BLL.Common();
            string str = CommonBLL.GetGetRejectTaxSqlByYear(FYear);
            string strwhere1 = "";
            if (str != "" && str != "( NULL)     ")
            {
                strwhere1 = @"   NOT EXISTS (SELECT  ZSXH
         FROM fund.V_SB_ZSXX s WHERE (" + str + @")  AND
                                   r.FDataSource = s.FDataSource AND
                                   r.ZSXH = s.ZSXH ) and DATEDIFF(DAY,RKRQ,'" + FYear + "-01-01')<=0 AND DATEDIFF(DAY,RKRQ,'" + FYear + "-12-31')>=0 ";
            }
            else
            {
                strwhere1 = @" DATEDIFF(DAY,RKRQ,'" + FYear + "-01-01')<=0 AND DATEDIFF(DAY,RKRQ,'" + FYear + "-12-31')>=0 ";
            }

            string year2 = (int.Parse(FYear) - 1).ToString();
            string str2 = CommonBLL.GetGetRejectTaxSqlByYear(year2);
            string strwhere2 = "";
            if (str != "" && str != "( NULL)     ")
            {
                strwhere2 = @"   NOT EXISTS (SELECT  ZSXH
         FROM fund.V_SB_ZSXX s WHERE (" + str + @")  AND
                                   r.FDataSource = s.FDataSource AND
                                   r.ZSXH = s.ZSXH ) and DATEDIFF(DAY,RKRQ,'" + year2 + "-01-01')<=0 AND DATEDIFF(DAY,RKRQ,'" + year2 + "-12-31')>=0 ";
            }
            else
            {
                strwhere2 = @" DATEDIFF(DAY,RKRQ,'" + year2 + "-01-01')<=0 AND DATEDIFF(DAY,RKRQ,'" + year2 + "-12-31')>=0 ";
            }

            StringBuilder strSql = new StringBuilder();

            strSql.Append(@"SELECT y.NSRBM,y.NSRMC, z.*,w.* FROM (
SELECT *,(" + sumstr1 + @") AS sumse FROM (
SELECT NSRDZDAH," + strwhere3 + @"
 FROM fund.V_SB_ZSXX r  
 where    " + strwhere1 + @"
          GROUP BY NSRDZDAH,YEAR(RKRQ)
          ) AS a WHERE " + sumstr1 + @" >0
         ) AS z
         LEFT JOIN (
         SELECT *,(" + sumstr2 + @") AS ysumse FROM (
SELECT NSRDZDAH as YNSRDZDAH," + strwhere4 + @"
 FROM fund.V_SB_ZSXX r  
 where   " + strwhere2 + @"
          GROUP BY NSRDZDAH,YEAR(RKRQ)
          ) AS a WHERE " + sumstr2 + @" >0
          ) w ON z.NSRDZDAH = w.YNSRDZDAH   LEFT JOIN fund.V_DJ_NSRXX y ON z.NSRDZDAH=y.NSRDZDAH WHERE z.sumse-w.ysumse>" + AddCredits);
            if (filter.Trim() != "")
            {
                strSql.Append(" and " + filter);
            }

            DataSet ds = SB_ZSXXBLL.GetAddCredits(strSql.ToString());
            ViewData["AddCredits"] = AddCredits;
            ViewData["year"] = FYear;
            DataTable dt = GetDate(ds, FYear, list);

            List<Model.XlsModel> xlsModelList = new List<Model.XlsModel>();
            int totalRowCount = 2;

            Model.XlsModel xlsModel = new Model.XlsModel();
            xlsModel.RowSpan = 2;
            xlsModel.RowIndex = totalRowCount;
            xlsModel.Title = "序号";
            xlsModel.HAlign = Model.XlsModel.HorizontalAlign.Center;

            xlsModelList.Add(xlsModel);

             xlsModel = new Model.XlsModel();
            xlsModel.RowSpan = 2;
            xlsModel.RowIndex = totalRowCount;
            xlsModel.Title = "纳税编码";
            xlsModel.HAlign = Model.XlsModel.HorizontalAlign.Center;

            xlsModelList.Add(xlsModel);

            xlsModel = new Model.XlsModel();
            xlsModel.RowSpan = 2;
            xlsModel.RowIndex = totalRowCount;
            xlsModel.Title = "企业名称";
            xlsModel.HAlign = Model.XlsModel.HorizontalAlign.Center;

            xlsModelList.Add(xlsModel);


            xlsModel = new Model.XlsModel();
            xlsModel.ColSpan = list.Count + 1;
            xlsModel.RowIndex = totalRowCount;
            xlsModel.Title = FYear + "年";
            xlsModel.HAlign = Model.XlsModel.HorizontalAlign.Center;
            xlsModelList.Add(xlsModel);

            xlsModel = new Model.XlsModel();
            xlsModel.ColSpan = list.Count + 1;
            xlsModel.RowIndex = totalRowCount;
            xlsModel.Title = year2 + "年";
            xlsModel.HAlign = Model.XlsModel.HorizontalAlign.Center;
            xlsModelList.Add(xlsModel);

            xlsModel = new Model.XlsModel();
            xlsModel.RowSpan = 2;
            xlsModel.RowIndex = totalRowCount;
            xlsModel.Title = "合计增加额(元)";
            xlsModel.HAlign = Model.XlsModel.HorizontalAlign.Center;
            xlsModelList.Add(xlsModel);

            totalRowCount++;


            foreach (Model.TaxClassAllowance tc in list)
            {
                xlsModel = new Model.XlsModel();
                xlsModel.ColSpan = 1;
                xlsModel.RowIndex = totalRowCount;
                xlsModel.Title = tc.FTaxClassAllowanceName;
                xlsModel.HAlign = Model.XlsModel.HorizontalAlign.Center;
                xlsModelList.Add(xlsModel);
            }

            xlsModel = new Model.XlsModel();
            xlsModel.ColSpan = 1;
            xlsModel.RowIndex = totalRowCount;
            xlsModel.Title = "合计";
            xlsModel.HAlign = Model.XlsModel.HorizontalAlign.Center;
            xlsModelList.Add(xlsModel);


            foreach (Model.TaxClassAllowance tc in list)
            {
                xlsModel = new Model.XlsModel();
                xlsModel.ColSpan = 1;
                xlsModel.RowIndex = totalRowCount;
                xlsModel.Title = tc.FTaxClassAllowanceName;
                xlsModel.HAlign = Model.XlsModel.HorizontalAlign.Center;
                xlsModelList.Add(xlsModel);
            }

            xlsModel = new Model.XlsModel();
            xlsModel.ColSpan = 1;
            xlsModel.RowIndex = totalRowCount;
            xlsModel.Title = "合计";
            xlsModel.HAlign = Model.XlsModel.HorizontalAlign.Center;
            xlsModelList.Add(xlsModel);


            xlsModel = new Model.XlsModel();
            xlsModel.ColSpan = list.Count * 2 + 6;
            xlsModel.RowIndex = 1;
            xlsModel.BottomLineStyle = 0;
            xlsModel.RightLineStyle = 0;
            xlsModel.LeftLineStyle = 0;
            xlsModel.TopLineStyle = 0;
            xlsModel.Title = "制表日期：" + DateTime.Now.ToString("yyyy年MM月dd日");
            xlsModel.HAlign = Model.XlsModel.HorizontalAlign.Center;
            xlsModelList.Add(xlsModel);

            for (int z = 0; z < dt.Rows.Count; z++)
            {
                totalRowCount++;
                foreach (System.Data.DataColumn dc in dt.Columns)
                {

                    decimal d = 0;
                    if (decimal.TryParse(dt.Rows[z][dc.ColumnName].ToString(), out d))
                    {
                        if (dc.ColumnName.Contains("bl"))
                        {
                            xlsModel = new Model.XlsModel();
                            xlsModel.RowIndex = totalRowCount;
                            xlsModel.HAlign = Model.XlsModel.HorizontalAlign.Right;
                            xlsModel.Title = decimal.Round(decimal.Parse(dt.Rows[z][dc.ColumnName].ToString())).ToString();
                            xlsModelList.Add(xlsModel);
                        }
                        else if (dc.ColumnName.Contains("xh"))
                        {
                            xlsModel = new Model.XlsModel();
                            xlsModel.RowIndex = totalRowCount;
                            xlsModel.HAlign = Model.XlsModel.HorizontalAlign.Center;
                            xlsModel.Title = decimal.Round(decimal.Parse(dt.Rows[z][dc.ColumnName].ToString())).ToString();
                            xlsModelList.Add(xlsModel);
                        }
                        else
                        {
                            xlsModel = new Model.XlsModel();
                            xlsModel.RowIndex = totalRowCount;
                            xlsModel.HAlign = Model.XlsModel.HorizontalAlign.Right;
                            xlsModel.Title = dt.Rows[z][dc.ColumnName].ToString();
                            xlsModelList.Add(xlsModel);
                        }
                    }
                    else
                    {
                        if (dc.ColumnName.Contains("NSRBM"))
                        {
                            xlsModel = new Model.XlsModel();
                            xlsModel.RowIndex = totalRowCount;
                            xlsModel.Title = dt.Rows[z][dc.ColumnName].ToString();
                            xlsModel.HAlign = Model.XlsModel.HorizontalAlign.Center;
                            xlsModelList.Add(xlsModel);
                        }
                        else
                        {
                            xlsModel = new Model.XlsModel();
                            xlsModel.RowIndex = totalRowCount;
                            xlsModel.Title = dt.Rows[z][dc.ColumnName].ToString();
                            xlsModel.HAlign = Model.XlsModel.HorizontalAlign.Left;
                            xlsModelList.Add(xlsModel);
                        }
                    }

                }
            }

            List<Model.XlsModel_Column> xlsModelColumns = new List<Model.XlsModel_Column>();
            xlsModelColumns.Add(new Model.XlsModel_Column()
            {
                ColumnIndexStart = 0,
                ColumnIndexEnd = 30,
                Width = 10
            });

            List<Model.XlsModel_Row> xlsModelRows = new List<Model.XlsModel_Row>();
            ushort rowCount = (ushort)(totalRowCount);
            xlsModelRows.Add(new Model.XlsModel_Row()
            {
                RowIndexStart = 1,
                RowIndexEnd = 1,
                RowHeight = 23
            });

            xlsModelRows.Add(new Model.XlsModel_Row()
            {
                RowIndexStart = 2,
                RowIndexEnd = 7,
                RowHeight = 12

            });
            xlsModelRows.Add(new Model.XlsModel_Row()
            {
                RowIndexStart = 8,
                RowIndexEnd = rowCount,
                RowHeight = 15

            });

            Model.ExcelTitleFont excelTitleFont = new Model.ExcelTitleFont()
            {
                FontName = "宋体",
                FontSize = 18,
                Bold = true
            };

            byte[] b = Common.ExcelClass.ExportToExcelReturnByte("", FYear + "年度企业增收贡献奖计算表", FYear + "年度企业增收贡献奖计算表", excelTitleFont, totalRowCount, xlsModelList, xlsModelColumns, xlsModelRows);

            string name = FYear + "年度企业增收贡献奖计算表.xls";
            return File(b, "application/vnd.ms-excel", HttpUtility.UrlEncode(name));
            //return GridViewExtension.ExportToXls(CreateExportGridViewSettings(FYear), dt, HttpUtility.UrlEncode("增收贡献表.xls"), true);
        }

       
        static GridViewSettings exportGridViewSettings;
        //public static GridViewSettings ExportGridViewSettings
        //{
        //    get
        //    {
        //        if (exportGridViewSettings == null)
        //            exportGridViewSettings = CreateExportGridViewSettings();
        //        return exportGridViewSettings;
        //    }
        //}

        public static GridViewSettings CreateExportGridViewSettings(string year)
        {
            var ss = new GridViewSettings();
            ss.Name = "gvEditing";
            ss.KeyFieldName = "NSRBM";

            ss.CallbackRouteValues = new { Controller = "QueryAddCredits", Action = "QueryAddCreditsListPartial" };
            ss.Width = System.Web.UI.WebControls.Unit.Percentage(100);
            ss.SettingsPager.PageSize = EnterpriseFund.Common.GlobalConstant.CONSTRING_PAGESIZE;
            //ss.Columns.Add("NSRDZDAH", "纳税人电子档案号");
            ss.Columns.Add("NSRSBH", "纳税人识别号");
            ss.Columns.Add("NSRBM", "纳税人编码");
            ss.Columns.Add("NSRMC", "纳税人名称");
            BLL.TaxClassAllowance taxClassAllowanceBLL = new BLL.TaxClassAllowance();
            List<Model.TaxClassAllowance> TaxClassAllowanceList = taxClassAllowanceBLL.GetModelList1("FYear='" + year + "'");
            foreach (Model.TaxClassAllowance t in TaxClassAllowanceList)
            {
                ss.Columns.Add(t.FTaxClassAllowanceNo, t.FTaxClassAllowanceName);
            }

            ss.Settings.ShowGroupPanel = true;


            ss.SettingsBehavior.EnableCustomizationWindow = true;
			
			
            ss.SettingsLoadingPanel.Text = "数据读取中...";
            ss.ClientSideEvents.BeginCallback = "function(s,e){OnBeginCallback(s,e)}";
            ss.CommandColumn.Visible = false;

            ss.DataBinding = (sender, e) =>
            {
                ASPxGridView grid = (ASPxGridView)sender;
                for (int i = 0; i < grid.AllColumns.Count; i++)
                {
                    if (grid.AllColumns[i].HeaderStyle.HorizontalAlign == System.Web.UI.WebControls.HorizontalAlign.NotSet)
                    {
                        grid.AllColumns[i].HeaderStyle.HorizontalAlign = System.Web.UI.WebControls.HorizontalAlign.Center;
                    }
                }
            };
            ss.PreRender = ss.BeforeGetCallbackResult = (sender, e) =>
            {


                MVCxGridView gridView = sender as MVCxGridView;
                MVCxGridViewState gridViewState = new MVCxGridViewState(gridView);
                OperateSession.SetToCache(gridViewState, "QueryAddCredits");


            };
            return ss;
        }

    }
}
